# Maintainer: Jaroslav Lichtblau <svetlemodry@archlinux.org>

_realname=sdcv
pkgbase="mingw-w64-${_realname}"
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.5.3
pkgrel=1
pkgdesc="StarDict Console Version"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://dushistov.github.io/sdcv/"
license=('GPL')
depends=(
  "${MINGW_PACKAGE_PREFIX}-glib2"
  "${MINGW_PACKAGE_PREFIX}-readline"
  "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-ninja"
  "${MINGW_PACKAGE_PREFIX}-cc")
source=(${_realname}-$pkgver.tar.gz::https://github.com/Dushistov/${_realname}/archive/v$pkgver.tar.gz
        "001-sdcv-0.5.3-fix-mingw-build.patch")
sha256sums=('75fb95b1607fdd2fb9f7795d3432d295904614150575ae539202f680499803c9'
            'ad23ea0f819630b6645a9f641f5f016dd7ff7c9edb665c7462b84b4552493849')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i "${srcdir}/001-sdcv-0.5.3-fix-mingw-build.patch"
}

build() {
  cd ${_realname}-${pkgver}

  rm -rf ./build
  install -d build
  cd build

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      -DBUILD_TESTS=True \
      -DCMAKE_BUILD_TYPE=Release \
      ..

  cmake --build .
  cmake --build . --target lang
}

check() {
  echo "Checking..."
  cd ${_realname}-${pkgver}/build

  ctest
}

package() {
  echo "Packing..."
  cd ${_realname}-${pkgver}/build

  DESTDIR="${pkgdir}" cmake --install .
}
